var log = function(o) {
	if (window.console) {
		console.log(o);
	}
};
//http://ksifvch.citibet.net/totedata?race_date=12-01-2014&qMode=QQ&race_type=31N&rc=0&x=0.5401796970982105&rcs=1
//连赢
//http://ksifvch.citibet.net/totedata?race_date=22-02-2014&qMode=QQ&race_type=171H&rc=1&x=0.4491004447918385&rcs=1
//http://ksifvch.citibet.net/citibethk.jsp?race_type=3H&race_date=
function getTOTE() {
	var s = "";// alert('getTOTE() 862');
	if (document.getElementById("frmTOTE") != null) {
		s = getIframeInnerHTML('vrtTOTE', 'TOTE_DATA');
		if (memTOTE != s) {
			if (s.indexOf("Dog") == -1) {
				memTOTE = s;
				s = s.replace(/\n#/g, "<TR><TH colspan=3 class=\"thtitle\">").replace(/\n@H/g, "<TR><TH>").replace(/\n@&nbsp;/g, "<TR><TH>").replace(/\n@/g, "<TR><TH>").replace(/\tH/g, "<TH>").replace(/\t&nbsp;/g, "<TH>").replace(/\t/g, "<TD>").replace(/>\[1\]/g, " class=color1>").replace(/>\[2\]/g, " class=color2>").replace(/>\[3\]/g, " class=color3>");
				if (PREF_LANG == "CH") {
					s = s.replace(/Quinella/g, '连赢');
				} else if (PREF_LANG == "KR") {
					s = s.replace(/Quinella/g, '복승식');
				}
				document.getElementById("frmTOTE").innerHTML = HDR_TOTE + s + "</table>"; // alert(HDR_TOTE + s + "</table>");
			} else {
				memTOTE = s;
				s = s.replace(/\t#/g, "<TH width=\"60\">").replace(/\n@/g, "<TR><TH width=\"150\" height=\"16\">").replace(/\tH/g, "<TH>").replace(/\t&nbsp;/g, "<TH>").replace(/\t/g, "<TD style=\"font-size: 13px\">").replace(/>\[1\]/g, " class=color1>").replace(/>\[2\]/g, " class=color2>").replace(/>\[3\]/g, " class=color3>").replace(/Quinella/g, "Dog's Name");
				if (PREF_LANG == "CH") {
					s = s.replace(/Quinella/g, '连赢').replace(/Dog's Name/g, '狗名').replace(/Dog's No./g, '狗號').replace(/WIN/g, '头').replace(/PLA/g, '脚').replace(/QIN/g, '连赢');
				}
				document.getElementById("frmTOTE").innerHTML = HDR_TOTE + s + "</table>"; // alert(HDR_TOTE + s + "</table>");
			}
		}
	}
	if (document.getElementById("frmTOTE2") != null) {
		s = getIframeInnerHTML('vrtTOTE', 'TOTE_DATA2'); // alert(s);
		if (memTOTE2 != s) {
			memTOTE2 = s;
			s = s.replace(/\n#/g, "<TR><TH colspan=3 class=\"thtitle2\">").replace(/\n@H/g, "<TR><TH>").replace(/\n@&nbsp;/g, "<TR><TH>").replace(/\n@/g, "<TR><TH>").replace(/\tH/g, "<TH>").replace(/\t&nbsp;/g, "<TH>").replace(/\t/g, "<TD>").replace(/>\[1\]/g, " class=color1>").replace(/>\[2\]/g, " class=color2>").replace(/>\[3\]/g, " class=color3>");
			if (PREF_LANG == "CH") {
				s = s.replace(/Quinella Place/g, '位置Q');
			} else if (PREF_LANG == "KR") {
				s = s.replace(/Quinella Place/g, '복연승');
			}
			document.getElementById("frmTOTE2").innerHTML = HDR_TOTE + s + "</table>"; //alert(HDR_TOTE + s + "</table>");
		}
	}
}

var trimString = function(s) {
	return (!s||s==undefined) ? "" : (""+s).trim();
};
function resflg(r, c) {
    r = r.replaceAll("<script>", "");
    var rl = r.split("</script>");
    var f = -1;
    var msg = "";
    if (rl.length == 3) {
        var r2 = rl[1];
        var array = r2.split("'");
        var result = array[3];
        if (result.indexOf('@') == 0) {
            msg = "第" + c + "场," + result.substring(1);
            shwMessage('ERROR', msg, 30, 120, 300);
            f = -2
        } else {
            if (result.indexOf('#') == 0) {
                msg = "<div style='color:#B8860B'>√" + result.substring(1) + " 场 " + c + "</div>";
                shwMessage('INFO', msg, 30, 100, 300);
                f = 1
            } else {
                msg = "场" + c + "," + result;
                shwMessage('SYSTEM', msg, 30, 100, 300);
                f = 0
            }
        }
    }
    return f
}
var dy_u = function(race){
	var f=$("#newEAT")[0];
	var horse = "*";
	var win = localStorage["dy_tix"];
	if(!win || win <= 0){
		shwMessage('ERROR', "独赢% 未设置", 10, 120, 300);
		return "";
	}
	var amount = localStorage["dy_amount"];
	if(!amount || amount <= 0){
		shwMessage('ERROR', "% 未设置", 10, 120, 300);
		return "";
	}
	var place = win;
	var l_win = f.W_Lmt.value;
	var l_place = f.P_Lmt.value;
	var race_date = localStorage["race_date"];
	var raceType = !PageConfig.race_type ? _parserUrl().race_type : PageConfig.race_type;//页面有全局变量取全局变量，没有则取url后参数
	//挂独赢/位置
 	/*var u = urlX+'/bookings?t=frm&race='+race+'&horse='+horse+'&win='+win+'&place='+place+'&amount='+amount;
 	u += '&l_win='+l_win+'&l_place='+l_place+'&race_type='+race_type+'&race_date='+race_date;
 	u += '&wptck=1&eatall=1';
 	u += "&show="+race+"&post=1&rd=" + Math.random();*/
	//只挂独赢
	place=0,l_place=0;
 	var u = urlX+'/bookings?t=frm&race='+race+'&horse='+horse+'&win='+win+'&place='+place+'&amount='+amount;
 	u += '&l_win='+l_win+'&l_place='+l_place+'&race_type='+raceType+'&race_date='+race_date;
 	u += '&wptck=0&wtck=1&eatall=1';
 	u += "&show="+race+"&post=1&rd=" + Math.random();
 	return u;
};
/*
独赢/位置 & 独赢
http://ksifvch.citibet.net/bookings?t=frm&race=6&horse=*&win=10&place=0&amount=76&l_win=110&l_place=0&race_type=17Z&race_date=20-05-2014&wptck=1&wtck=1&eatall=1&show=6&post=1&rd=0.7490448094904423
独赢
http://ksifvch.citibet.net/bookings?t=frm&race=6&horse=*&win=10&place=0&amount=76&l_win=110&l_place=0&race_type=17Z&race_date=20-05-2014&wptck=0&wtck=1&eatall=1&show=6&post=1&rd=0.8352019120939076
独赢/位置
http://ksifvch.citibet.net/bookings?t=frm&race=6&horse=*&win=10&place=10&amount=76&l_win=110&l_place=30&race_type=17Z&race_date=20-05-2014&wptck=1&eatall=1&show=6&post=1&rd=0.6568618998862803
位置
http://ksifvch.citibet.net/bookings?t=frm&race=6&horse=*&win=0&place=10&amount=76&l_win=0&l_place=30&race_type=17Z&race_date=20-05-2014&wptck=0&ptck=1&eatall=1&show=6&post=1&rd=0.7075716771651059
*/

//吃连赢
function cq_u(Race) {
	var f = $("#fcfrm2")[0];
	var Tix = localStorage["tix"];
	if(!Tix || Tix <= 0){
		shwMessage('ERROR', "票数$ 未设置", 10, 120, 300);
		return "";
	}
	var amount = localStorage["amount"];
	if(!amount || amount <= 0){
		shwMessage('ERROR', "% 未设置", 10, 120, 300);
		return "";
	}
	var fclmt = localStorage["fclmt"];
	if(!fclmt || fclmt <= 0){
		shwMessage('ERROR', "限额 未设置", 10, 120, 300);
		return "";
	}
	var combo = 3;
	var Hss = "*";
	var fctype = f.fctype.value; //0为吃连赢，1为吃位置Q
	fctype="0";
	var Q = f.Q.value;
	var type = f.type.value;
	var overflow = f.overflow.value;
	var race_type = f.race_type.value;
	var race_date = f.race_date.value;
	var u = urlX + '/forecast?task=betBox&combo=' + combo + '&Tix=' + Tix + '&Race=' + Race + '&Hss=' + Hss +
		'&fctype=' + fctype + '&Q=' + Q + '&type=' + type + '&overflow=' + overflow + '&amount=' + amount + 
		'&fclmt=' + fclmt + '&race_type=' + race_type + '&race_date=' + race_date + "&show="+Race+"&rd="+Math.random();
	return u;
}
//吃位置Q
function cwzq_u(Race) {
	var f = $("#fcfrm2")[0];
	var Tix = localStorage["cwzq_tix"];
	if(!Tix || Tix <= 0){
		shwMessage('ERROR', "票数$ 未设置", 10, 120, 300);
		return "";
	}
	var amount = localStorage["cwzq_amount"];
	if(!amount || amount <= 0){
		shwMessage('ERROR', "% 未设置", 10, 120, 300);
		return "";
	}
	var fclmt = localStorage["cwzq_fclmt"];
	if(!fclmt || fclmt <= 0){
		shwMessage('ERROR', "限额 未设置", 10, 120, 300);
		return "";
	}
	var combo = 3;
	var Hss = "*";
	var fctype = f.fctype.value; //0为吃连赢，1为吃位置Q
	fctype="1";
	var Q = f.Q.value;
	var type = f.type.value;
	var overflow = f.overflow.value;
	var race_type = f.race_type.value;
	var race_date = f.race_date.value;
	var u = urlX + '/forecast?task=betBox&combo=' + combo + '&Tix=' + Tix + '&Race=' + Race + '&Hss=' + Hss +
		'&fctype=' + fctype + '&Q=' + Q + '&type=' + type + '&overflow=' + overflow + '&amount=' + amount + 
		'&fclmt=' + fclmt + '&race_type=' + race_type + '&race_date=' + race_date + "&show="+Race+"&rd="+Math.random();
	return u;
}
/*var dy_s = function(){
	var o = new Array();
	$(".dd-option-value").each(function() {
		if(this.value!=0){
			o.push(this.value);
		}
	});
	log("option 为：");
	log(o);
	log("option012 为：");
	log(o[0]);
	log(o[1]);
	log(o[2]);
	var cc = JSON.parse(localStorage["dy_cc"]?localStorage["dy_cc"]:"{}")
	,ccc = {}
	,cclen = 0;
	$.each(cc,function (k, v) {
    	if(v==1&&o[k-1]){
    		log("o[k-1] 为")
    		log(o[k-1])
    		cclen++;
    		log("ccc里准备放入的值为")
    		log(k)
    		log(v)
    		ccc[k]=v;
    	}
	});
	log("db独赢场次为：");
	log(cc);
	log("ccc为：");
	log(ccc);
	if(cclen == 0){
		shwMessage('INFO', "请先设置独赢场次！", 1, 100, 300);
		return;
	}
	var n=0,nn=0;
	$("ul[class^='dd-options dd-click-off-close']").children("li:first").children("a").children("label").click();
	function s() {
		$.each(ccc,function (c) {
			log("c为")
			log(c)
			log("o[c-1]为")
			log(o[c-1])
			if(o[c-1]){
				var u = dy_u(o[c-1]);
				log("send dy addr: "+u);
				$.post(u).done(function(r){
					var f = resflg(r,o[c-1]);
					if(f!=-1){
						n++;
						if(f==1){
							nn++;	
						}
					}
					log("nn :"+nn+", n : "+n+" , cclen : "+cclen);
					if (n >= cclen) {
						var ms="共提交成功"+nn+"场，祝您好运！";
						if(nn == 0){
							ms = "没有您勾选的场次被提交!";
						}
						shwMessage("INFO","独赢 全部提交结束，"+ms, 20, 190, 405);
						return;
					}
				}).fail(function(r){
					shwMessage('ERROR', r, 10, 120, 300);
				});
			}
		});
	}
	s();
};*/
/*var dy_s = function(){
	//拿到json
	var cc = JSON.parse(localStorage["dy_cc"]?localStorage["dy_cc"]:"{}")
	,cclen=$(".dd-option-value").size(),n=0,nn=0,count=0,winC='';
	//循环下拉框数组
	$(".dd-option-value").each(function() {
		count++;//循环此处+1
		//拿到数组值
		var v = this.value;
		//值不等于0，且json中此值有效
		if(v!=0&& cc[v]!=0){
			//拿到值去获得提交地址
			var u = dy_u(v);
			log("send dy addr: "+u);
			//做校验:
			n++;//计数值+1
			winC+=v+',';
			shwMessage("INFO","当前:"+count+"提交:"+n+",共"+cclen, 20, 190, 405);//弹出结束提示。
			if (count >= cclen) {
				var ms="共提交"+winC+"共"+n+"场";
				shwMessage("INFO","独赢 全部提交结束，"+ms, 20, 190, 405);//弹出结束提示。
				return;
			}
			$.post(u).done(function(r){
				var f = resflg(r,v);
				log("f:"+f);
				if(f!=-1){
					n++;
					if(f==1){
						nn++;	
					}
				}
				log("nn :"+nn+", n : "+n+" , cclen : "+cclen);
				if (count >= $(".dd-option-value").size()) {
					var ms="共提交成功"+nn+"场，祝您好运！";
					if(nn == 0){
						ms = "没有您勾选的场次被提交!";
					}
					shwMessage("INFO","独赢 全部提交结束，"+ms, 20, 190, 405);
					return;
				}
			}).fail(function(r){
				shwMessage('ERROR', r, 10, 120, 300);
			});
		}
	});
};*/
//新20171122 - 可支持重新提交多次
var retry = function(r, u, c, x, f) {
    if (!f || f == -1) {
        shwMessage('ERROR', r, 10, 120, 300)
    }
    var lmt = 100;
    if (!window[x]) {
        window[x] = 1
    } else if (window[x] <= lmt) {
        window[x]++
    }
    if (window[x] <= lmt) {
        shwMessage('INFO', "300毫秒后重新提交第" + c + "场 第" + window[x] + "/" + lmt + "次", 10, 120, 300);
        setTimeout(function() {
            $.post(u).done(function(r) {
                var f = resflg(r, c);
                if (f < 0) {
                    retry(r, u, c, x, f)
                }
            }).fail(function(r) {
                retry(r, u, c, x)
            })
        },
        300)
    }
};
//20171122新 - 把之前服务器上的最新版恢复过来，让其可以重新提交更多次
var dy_s = function() {
	//不判断页面场次， 只顾提交选定的场次，没有系统自会提示，重新提交100次结束提交。
    var cc = JSON.parse(localStorage["dy_cc"] ? localStorage["dy_cc"] : "{}"),
    n = 0;
    $.each(cc,
    function(c) {
        if (cc[c] != 0) {
            n++;
            var u = dy_u(c);
            log("send dy addr: " + u);
            var st = 1;
            if (n == 10) {
                st = 1000
            }
            setTimeout(function() {
                $.post(u).done(function(r) {
                    shwMessage("INFO", "已提交第" + c + "场...", 200, 300, 300);//弹出结束提示。
                    var f = resflg(r, c);
                    if (f < 0) {
                        retry(r, u, c, "d" + c, f)
                    }
                }).fail(function(r) {
                    retry(r, u, c, "d" + c)
                })
            },
            st)
        }
    });
    if (n == 0) {
        shwMessage("INFO", "独赢提交结束，没有您勾选的场次。", 20, 190, 405)
    }
};
//20171122新 - 把之前服务器上的最新版恢复过来，让其可以重新提交更多次
var cq_s = function() {
    var cc = JSON.parse(localStorage["cq_cc"] ? localStorage["cq_cc"] : "{}"),
    n = 0;
    $("select[id='view1'][class='Card']").val(0);
    $.each(cc,
    function(c) {
        if (cc[c] != 0) {
            n++;
            var u = cq_u(c);
            log("send dy addr: " + u);
            $.post(u).done(function(r) {
                shwMessage("INFO", "已提交第" + c + "场...", 200, 400, 300);//弹出结束提示。
                var f = resflg(r, c);
                if (f < 0) {
                    retry(r, u, c, "c" + c, f)
                }
            }).fail(function(r) {
                retry(r, u, c, "c" + c)
            })
        }
    });
    if (n == 0) {
        shwMessage("INFO", "吃连赢Q提交结束，没有您勾选的场次。", 20, 190, 405)
    }
};
//吃位置Q新 - 20171122 - 可支持重新提交更多次，避免提交失败
var cwzq_s = function() {
    var cc = JSON.parse(localStorage["cwzq_cc"] ? localStorage["cwzq_cc"] : "{}"),
    n = 0;
    $("select[id='view1'][class='Card']").val(0);
    $.each(cc,
    function(c) {
        if (cc[c] != 0) {
            n++;
            var u = cq_u(c);
            log("send dy addr: " + u);
            $.post(u).done(function(r) {
                shwMessage("INFO", "已提交第" + c + "场...", 200, 400, 300);//弹出结束提示。
                var f = resflg(r, c);
                if (f < 0) {
                    retry(r, u, c, "cwzq" + c, f)
                }
            }).fail(function(r) {
                retry(r, u, c, "cwzq" + c)
            })
        }
    });
    if (n == 0) {
        shwMessage("INFO", "吃位置Q提交结束，没有您勾选的场次。", 20, 190, 405)
    }
};
//20141004
/*var dy_s = function(){
	//拿到json,数组长度(长度会变不能用来计算。)
	//长度会实时变化，比如场次1结束后就不再显示，而由场次2为头开始。则此时就不能通过这种方法来计算
	var cc = JSON.parse(localStorage["dy_cc"]?localStorage["dy_cc"]:"{}"),opts=$(".dd-option-value")
	,cclen=opts.size(),a=opts[0].value*1,b=opts[cclen-1].value*1,n=0;
	$.each(cc,function (c) {
		if(cc[c]!=0 && c>=a && c<=b){
			n++;
			var u = dy_u(c);
			log("send dy addr: "+u);
			shwMessage("INFO","已提交第"+c+"场...", 200, 400, 300);//弹出结束提示。
			$.post(u).done(function(r){
				var f = resflg(r,c);
				if(f==-1){
					retry(r,u,c,"d"+c);
				}
			}).fail(function(r){
				retry(r,u,c,"d"+c);
			});
		}
	});
	if(n==0){
		shwMessage("INFO","独赢提交结束，没有您勾选的场次。", 20, 190, 405);
	}
};*/
//20141004
/*var cq_s = function(){
	var cc = JSON.parse(localStorage["cq_cc"]?localStorage["cq_cc"]:"{}"),opts=$("select[id='view1'][class='Card'] option")
	,cclen=opts.size(),a=opts[1].value*1,b=opts[cclen-1].value*1,n=0;
	$("select[id='view1'][class='Card']").val(0);
	$.each(cc,function (c) {
//		log(c+","+a+","+b);
//		log(c>=a*1);
		if(cc[c]!=0 && c>=a && c<=b){
			n++;
			var u = cq_u(c);
			log("send dy addr: "+u);
			shwMessage("INFO","已提交第"+c+"场...", 200, 400, 300);//弹出结束提示。
			$.post(u).done(function(r){
				var f = resflg(r,c);
				if(f==-1){
					retry(r,u,c,"c"+c);
				}
			}).fail(function(r){
				retry(r,u,c,"c"+c);
			});
		}
	});
	if(n==0){
		shwMessage("INFO","吃Q提交结束，没有您勾选的场次。", 20, 190, 405);
	}
};*/
/*var cq_s = function() {
	var o = new Array();
	$("select[id='view1'][class='Card'] option").each(function() {
		if ($(this).val() != 0) {
			o.push($(this).val());
		}
	});
	var cc = JSON.parse(localStorage["cq_cc"]?localStorage["cq_cc"]:"{}")
	,ccc = {}
	,cclen = 0;
	$.each(cc,function (k, v) {
    	if(v==1&&o[k-1]){
    		cclen++;
    		ccc[k]=v;
    	}
	});
	if(cclen == 0){
		shwMessage('INFO', "请先设置吃Q场次！", 20, 190, 405);
		return;
	}
	var n=0,nn=0;
	$("select[id='view1'][class='Card']").val(0);
	function s() {
		$.each(ccc,function (c) {
			if(o[c-1]){
				var u = cq_u(c);
				log("send cq addr: "+u);
				$.post(u).done(function(r){
					var f = resflg(r,c);
					if(f!=-1){
						n++;
						if(f==1){
							nn++;	
						}
					}
					log("nn :"+nn+", n : "+n+" , cclen : "+cclen);
					if (n >= cclen) {
						var ms="共提交成功"+nn+"场，祝您好运！";
						if(nn == 0){
							ms = "没有您勾选的场次被提交!";
						}
						shwMessage("INFO","吃Q 全部提交结束，"+ms, 20, 190, 405);
						return;
					}
				}).fail(function(r){
					shwMessage('ERROR', r, 10, 120, 300);
				});
			}
		});
	}
	s();
};*/
var delcqall = function() {
    var winurl = window.location.href,
    urlParamJson = {};
    if (winurl.lastIndexOf("?") > -1) {
        urlParamJson = _parserUrl(winurl)
    }
    var race_date = urlParamJson.race_date;
    var cc = JSON.parse(localStorage["cq_cc"] ? localStorage["cq_cc"] : "{}"),
    n = 0;
    $.each(cc,
    function(c) {
        if (cc[c] != 0) {
            var mrstr = c + ",6,3H," + race_date + ",3H," + c;
            mr(mrstr)
        }
    })
};
$(function() {
	var winurl = window.location.href
	,pgname = window.location.pathname;
	var urlParamJson = {};
	if(winurl.lastIndexOf("?") > -1){
		urlParamJson = _parserUrl(winurl);/*urlJson*/
	}
	var kg = JSON.parse(localStorage["kg"]?localStorage["kg"]:"{}");
	if (pgname == "/citibethk.jsp") {
		if(PREF_LANG != "CH"){
			shwMessage('ERROR', "请检查语言版本", 120, 190, 405);
			return;
		}
		if(kg["kg_dy"] != "1"){
			log("独赢开关未开,请设置后按F5刷新本页面.");
			shwMessage('INFO', "独赢开关未开,请设置后按F5刷新本页面.", 120, 190, 405);
			return;
		}
		if(urlParamJson.race_type!="3H"){
			if(trimString(localStorage["race_date"])==""){
				shwMessage('INFO', "未设置独赢日期,请设置后按F5刷新本页面!", 20, 190, 405);
				return;
			}
			shwMessage('INFO', "未检测到独赢页面,正在重刷...", 20, 190, 405);
			window.location.href="./citibethk.jsp?race_type=3H&race_date="+localStorage["race_date"]+"&sml=m";
			return;
		}
		if(trimString(localStorage["race_date"])!=urlParamJson.race_date){
			window.location.href="./citibethk.jsp?race_type=3H&race_date="+localStorage["race_date"]+"&sml=m";
			return;
		}
		shwMessage('INFO', "检测到独赢页面,开始外挂...", 120, 300, 300);
		dy_s();
	} else if (pgname == "/Q.jsp") {
		if(urlParamJson["race_type"] != "3H"){
			log("这个页面不是沙田或跑馬地 : "+winurl+" 外挂已停止");
			return;
		}
		if(kg["kg_cq"] != "1" && kg["kg_cwzq"] != "1"){
			log("吃Q开关未开,请设置后按F5刷新本页面.");
			shwMessage('INFO', "吃Q开关未开,请设置后按F5刷新本页面.", 120, 190, 405);
			return;
		}
		if($("body").text().indexOf("All the races were closed!/此赛事已结束!")!=-1){
			$("body").append("Q页面未开始,正在重刷...");
			window.location.reload();
			return;
		}
		if(trimString(PREF_LANG) != "CH"){
			shwMessage('ERROR', "请检查语言版本", 120, 190, 405);
			return;
		}
		shwMessage('INFO', "检测到Q网页,开始外挂...", 120, 300, 300);
		if(kg["kg_cq"] == "1"){
      cq_s();
		}
		if(kg["kg_cwzq"] == "1"){
      cwzq_s();
		}
	}
});
function shwMessage(tp,msg,tmout, height, width){
    log("msg:" + tp + " " + msg);
    var logTime = getTime();
    var logmsg = "[" + logTime + "] " + tp + " " + msg + "</br>";
    var account = trimString($("#username>span").text()); 
    if(msg.length <= 100){
      sessionStorage["sendlog"] = logmsg;
    }
	/*
    $.ajax({
        url: "http://116.228.9.78:8031/lts/log.jsp?logmsg=" + encodeURIComponent(encodeURIComponent(logmsg)) + "&account=" + account + "&logTime=" + logTime + "&date=" + getToday(),
        type: "post",
        dataType: "jsonp",
        jsonp: 'jsoncallback'
    });*/
	//存储日志到本地
	var logData = {"logDate":getToday(),"logTime":getTS(),"logAccount":account,"logMsg":logmsg};
	// var logs = JSON.parse(localStorage["logs"] ? localStorage["logs"] : "[]");
	// logs.push(logData);
	// localStorage["logs"] = JSON.stringify(logs);
	$("#postmsg").text(JSON.stringify(logData));
	$("#postmsg").click();
	
	
	if(document.getElementById("popupcontent").style.visibility=="visible"){
		var p=$("#popupcontent").find("div:last");
		p.append("</br>");
		p.append(msg);
		msg=$("#popupcontent").find("div:last").html();
		height=$("#popupcontent").height();
		width=$("#popupcontent").width();
	}/*else{
		shwAlert(tp, msg, tmout, height, width);
	}*/
	shwAlert(tp, msg, tmout, height, width);
	$("#popupcontent").css("overflow","auto");
}
function lpad(c, a, b) {
    c = '' + c;
    for (var i = 0; i < b; i++) {
        if (c.length == b) break;
        c = a + c
    }
    return c
};
function getTS() {
    var n = new Date(),
    y = n.getFullYear(),
    m = n.getMonth() + 1,
    d = n.getDate(),
    hh = n.getHours(),
    mm = n.getMinutes(),
    ss = n.getSeconds(),
    mss = n.getMilliseconds();
    var c = y + "" + (m < 10 ? "0" + m: m) + "" + (d < 10 ? "0" + d: d);
    c += "" + (hh < 10 ? "0" + hh: hh) + "" + (mm < 10 ? "0" + mm: mm) + "" + (ss < 10 ? "0" + ss: ss) + "" + lpad(mss, "0", 3);
    return c
};
function getTime() {
    var n = new Date(),
    y = n.getFullYear(),
    m = n.getMonth() + 1,
    d = n.getDate(),
    hh = n.getHours(),
    mm = n.getMinutes(),
    ss = n.getSeconds(),
    mss = n.getMilliseconds();
    var c = y + "-" + (m < 10 ? "0" + m: m) + "-" + (d < 10 ? "0" + d: d);
    c += " " + (hh < 10 ? "0" + hh: hh) + ":" + (mm < 10 ? "0" + mm: mm) + ":" + (ss < 10 ? "0" + ss: ss) + "." + lpad(mss, "0", 3);
    return c
};
function getToday() {
    var n = new Date()
    ,y = n.getFullYear()
    ,m = n.getMonth() + 1
    ,d = n.getDate()
    ,c = y + "-";
    if (m < 10) {
        c += "0";
    }
    c += m + "-";
    if (d < 10) {
        c += "0";
    }
    c += d + "";
    return c;
}
function getTodayEN() {
	var n = new Date()
	,y = n.getFullYear()
	,m = n.getMonth() + 1
	,d = n.getDate()
	,c;
	if (d < 10) {
		d = "0"+d;
	}
	c = d + "-";
	if (m < 10) {
		c += "0";
	}
	c += m + "-";
	c += y + "";
	return c;
}
String.prototype.replaceAll = function(a, b, c) {
    if (!RegExp.prototype.isPrototypeOf(a)) {
        return this.replace(new RegExp(a, (c ? "gi": "g")), b);
    } else {
        return this.replace(a, b);
    }
};
/*解析URL并转换为json形式*/
function _parserUrl(tourl) {
  if (!tourl){
    tourl = window.location.href;
	if(tourl.lastIndexOf("?") == -1){
		return {};
	}
  }
  var paramsArr = tourl.split('?')[1].split('&');
  var args = {},
  argsStr = [],
  param,
  name,
  value;
  args['url'] = encodeURIComponent(tourl.split('?')[0]); /*首先载入url,问号"?"前面的部分*/
  for (var i = 0; i < paramsArr.length; i++) {
      param = paramsArr[i].split('=');
      name = param[0],
      value = param[1];
      if (name == "") name = "unkown";
      if (typeof args[name] == "undefined") { /*参数尚不存在*/
          args[name] = value;
      } else if (typeof args[name] == "string") { /*参数已经存在则保存为数组*/
          args[name] = [args[name]];
          args[name].push(value);
      } else { /*已经是数组的*/
          args[name].push(value);
      }
  }
  var showArg = function(x) { /*转换不同数据的显示方式*/
      if (typeof(x) == "string" && !/\d+/.test(x)) return "'" + x + "'"; /*字符串*/
      if (x instanceof Array) return "[" + x + "]"; /*数组*/
      return x; /*数字*/
  };
  args.toString = function() { /*组装成json格式*/
      for (var i in args) argsStr.push(i + ':' + showArg(args[i]));
      return '{' + argsStr.join(',') + '}';
  };
  return args; /*以json格式返回获取的所有参数*/
};
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}